<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //11.猜数字游戏     
        var rannum = parseInt(Math.random() * 1000);
        var count = 0;
        var num = window.prompt("请输入一个1000的数字:");
        // document.write(rannum);
        while (1) {
            count++;
            if (num == rannum) {
                document.write(rannum + '猜中，猜了' + count + '次<br>');
                break;
            }
            if (num > rannum) {
                // document.write('大了<br>');
                num = window.prompt("大了,请输入一个1000的数字:");
            }
            if (num < rannum) {
                // document.write('小了<br>');
                num = window.prompt("小了,请输入一个1000的数字:");
            }
        }
    </script>
</body>

</html>